<?

//Data loading
$title='Report ZBB/ZBK Not Yet Approved / Cash Out';
$type = GetParam("type","");

$perush = 'PT. AMPEL JAYA';

$page   = 'PAGE';
$TableName = "ais_memorial_z";
$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = ReportList ("", "", "");
if ($Result) $pdf->ReportTable($Result);
$pdf->Output();



function ReportList ($Space, $Index, $ParentID) 
{ 
	global $RS,$Index,$TableName,$type;
	$DBConnection   = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
	if (!$Index) $Index = 0;


    $SQL = " SELECT * FROM ".$TableName." ";           

    if (GetParam("fromDate",""))
    {
        list($day1,$month1,$year1) = explode("/",GetParam("fromDate",""));
        $FDate = "$year1-$month1-$day1";
    }

    if (GetParam("toDate",""))
    {
        list($day2,$month2,$year2) = explode("/",GetParam("toDate",""));
        $TDate = "$year2-$month2-$day2";
    }


    if ($FDate)
        if (strlen($WHERE)) $WHERE .= " AND tglbkt >= '".$FDate."' ";
        else $WHERE .= " tglbkt >= '".$FDate."' ";

    if ($TDate)
        if (strlen($WHERE)) $WHERE .= " AND tglbkt <= '".$TDate."' ";
        else $WHERE .= " tglbkt <= '".$TDate."' ";
        
    if ($type)
        if (strlen($WHERE)) $WHERE .= " AND nobkt like '".$type."%' ";
        else $WHERE .= " nobkt like '".$type."%' ";
  
    if (strlen($WHERE)) $WHERE = " WHERE urut <> '999' AND ".$WHERE;
        else $WHERE = " WHERE urut <> '999' ";


    $SQL = $SQL.$WHERE;

    $SQL .= " ORDER BY memorial_id DESC ";

    $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
    return $MyResult;
    
}




class PDFReport extends PDF {

    function Header() 
    {
		
        global $title,$perush,$page,$DEFINE_FONT,$curr;
         
        //Initial Date 
        $FDate = GetParam("fromDate","");		
		$TDate = GetParam("toDate","");		
		$SystemDate = date("d/m/Y");		
		//End Initial Date
        
        if ($DEFINE_FONT==0) {
            $this->AddFont('arialn','','arialn.php');
            $DEFINE_FONT=1;
        }
		$this->SetFont('arialn','',12);
		$this->Cell(195,5,$perush,0,1,'C',0);
		$this->Cell(195,5,$title,0,1,'C',0);		
		$this->Cell(195,5,"REPORT FROM: ".GetParam("fromDate","")." TO: ".$TDate,0,1,'C',0);                		
		$this->Cell(195,5,$page." ".$this->PageNo(),0,1,'R',0);
		$this->Line(10,30,205,30);
		$this->Ln();
		$this->Ln();
		//Header

		//Column widths               
		$w=array(30,30,80,20,30);
		$this->SetFont('arialn','',8);

		$this->Cell($w[0],7,"NO. BK / BB",1,0,'C',0);
		$this->Cell($w[1],7,"Date of Transaction",1,0,'C',0);
		$this->Cell($w[2],7,"Description",1,0,'C',0);
		$this->Cell($w[3],7,"Currency",1,0,'C',0);
		$this->Cell($w[4],7,"Amount (in IDR)",1,0,'C',0);                
		
		$this->Ln();
		
    }

    function ReportTable($Result) {
        
        //Column widths
        $w=array(30,30,80,20,30);
        $TotalAmount = 0;
                        
        //Data
        foreach($Result as $row)
        {

			$no++;
							
			//Date Of Transaction
			list($year,$month,$day) = explode("-",$row["tglbkt"]);
			$FDate = "$day-$month-$year";                 
			
			if(strlen($row["uraian"]) > 50)
			{
				$more = " .....";
			}
			else
			{
				$more = "";
			}
						
			$this->Cell($w[0],6,$row["nobkt"],'LR',0,'C');                                
			$this->Cell($w[1],6,$FDate,'LR',0,'C');
			$this->Cell($w[2],6,substr($row["uraian"],0,50).$more,'LR',0,'L');							
			$this->Cell($w[3],6,$row["curr"],'LR',0,'C');					
			$this->Cell($w[4],6,number_format($row["jumlah"],2),'LR',0,'R');					
			$TotalAmount+= $row["jumlah"];							   
			$this->Ln();
                
        }


		$this->Cell($w[0]+$w[1]+$w[2]+$w[3],6,"TOTAL:",'LTR');
		$this->Cell($w[4],6,number_format($TotalAmount,2),'LTR',0,'R');
		$this->Ln();

       
    }

    function Footer() {
        $this->Cell(190,0,'','T');
    }

}


?>
